package com.biostime.qdingding.modules.qd.entity;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.biostime.qdingding.common.persistence.DataEntity;
import com.biostime.qdingding.modules.qd.promotions.DiscountChain;
import com.biostime.qdingding.modules.qd.promotions.Discountable;
import com.biostime.qdingding.modules.qd.utils.CalendarUtils;
import com.google.common.collect.Maps;

/**
 * 排课表Entity
 * @author phil
 * @version 2015-11-11
 */
public class Course extends DataEntity<Course> implements Discountable {

	private static final long serialVersionUID = 1L;
	
	private Integer type;//课程类型（0:普通课程，1户外课程）
	private Integer classroomId;// 上课教室
	private String classroom;// 上课教室
	private Integer sectionId;// 上课教室
	private String section;// 上课时间
	private Integer teacherId;// 主讲教师
	private String teacher;// 主讲老师
	private Integer teacher2Id;// 助教讲师
	private String teacher2;// 助教
	private Integer levelId;// 课程阶段
	private String clevel;// 课程阶段
	private Integer serialId;// 课程系列
	private String serial;// 课程系列
	private Integer themeId;// 课程主题
	private String theme;// 课程主题
	private String themeDesc;// 主题介绍
	private Date ondate;// 上课日期
	private Integer capacity;// 容量
	private Integer priceType;// 价格类型，目前分为忙时和闲时
	private String price;// 价格设置，浮动价格通过KVP的方式设置，不令做结构
	private int centerId;//早教中心编号
	private String label;//标签
	
	private int orders;//约课人数
	private int sigins;//签到人数
	
	//促销相关
	private int rank = 0;//学生排名
	private double priceNow = 0; //折扣前价格
	private int studentId = 0; //查看课程的学员编号
	private DiscountChain discountChain = new DiscountChain(); //优惠链
	private Map<String,Promotion> promotions = Maps.newHashMap(); //课程应该有的优惠
	//促销相关
	
	public Course(){
		super();
	}
	
	public Course(String id){
		super(id);
	}
	
	public Integer getClassroomId() {
		return classroomId;
	}

	public void setClassroomId(Integer classroomId) {
		this.classroomId = classroomId;
	}
	
	public String getClassroom() {
		return classroom;
	}

	public void setClassroom(String classroom) {
		this.classroom = classroom;
	}
	
	public String getWeekDay(){
		
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(this.ondate);
		int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
		
		return CalendarUtils.Weeks.get(weekDay);
	}
	
	public Integer getSectionId() {
		return sectionId;
	}

	public void setSectionId(Integer sectionId) {
		this.sectionId = sectionId;
	}

	public String getSection() {
		return section;
	}

	public void setSection(String section) {
		this.section = section;
	}

	public Date getOndate() {
		return ondate;
	}

	public void setOndate(Date ondate) {
		this.ondate = ondate;
	}

	public Integer getTeacherId() {
		return teacherId;
	}

	public void setTeacherId(Integer teacherId) {
		this.teacherId = teacherId;
	}
	
	public String getTeacher() {
		return teacher;
	}

	public void setTeacher(String teacher) {
		this.teacher = teacher;
	}
	
	public Integer getTeacher2Id() {
		return teacher2Id;
	}

	public void setTeacher2Id(Integer teacher2Id) {
		this.teacher2Id = teacher2Id;
	}
	
	public String getTeacher2() {
		return teacher2;
	}

	public void setTeacher2(String teacher2) {
		this.teacher2 = teacher2;
	}
	
	public Integer getLevelId() {
		return levelId;
	}

	public void setLevelId(Integer levelId) {
		this.levelId = levelId;
	}
		
	public String getClevel() {
		return clevel;
	}

	public void setClevel(String clevel) {
		this.clevel = clevel;
	}

	public Integer getSerialId() {
		return serialId;
	}

	public void setSerialId(Integer serialId) {
		this.serialId = serialId;
	}
	
	public String getSerial() {
		return serial;
	}

	public void setSerial(String serial) {
		this.serial = serial;
	}
	
	public Integer getThemeId() {
		return themeId;
	}

	public void setThemeId(Integer themeId) {
		this.themeId = themeId;
	}
	
	public String getTheme() {
		return theme;
	}

	public void setTheme(String theme) {
		this.theme = theme;
	}
	
	public String getThemeDesc() {
		return themeDesc;
	}

	public void setThemeDesc(String themeDesc) {
		this.themeDesc = themeDesc;
	}
	
	public Integer getCapacity() {
		return capacity;
	}

	public void setCapacity(Integer capacity) {
		this.capacity = capacity;
	}
	
	public Integer getPriceType() {
		return priceType;
	}

	public void setPriceType(Integer priceType) {
		this.priceType = priceType;
	}
	
	public String getPrice() {
		return price;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	public int getCenterId() {
		return centerId;
	}

	public void setCenterId(int centerId) {
		this.centerId = centerId;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public Map<String,Promotion> getPromotions() {
		return promotions;
	}

	public void setPromotions(Map<String,Promotion> promotions) {
		this.promotions = promotions;
	}
	
	/**优惠相关**/
	
	public void addPromotions(List<Promotion> ps){
		if(ps!=null && ps.size()>0){
			for(Promotion p : ps){
				addPromotion(p);
			}
		}
	}
	
	public void clearPromotions(){
		promotions.clear();
		discountChain.clear();
	}
	
	public void addPromotion(Promotion p){
		/**规则：忙时没有前三返10**/
		if(p.getTemplate().getFormula().equalsIgnoreCase("FirstNDiscountor") && priceType==0){
			return;
		}
		
		/**优惠**/
		promotions.put(p.getTemplate().getFormula(), p);
		/**打折器**/
		discountChain.addDiscountor(p.getTemplate().getFormula());
	}
	
	/**
	 * 打折课程
	 */
	public void discount(){
		/*打折课程*/
		discountChain.discount(this);
	}
	
	public double getPriceNow() {
		return priceNow;
	}

	public void setPriceNow(double priceNow) {
		this.priceNow = priceNow;
	}
	
	public int getStudentId() {
		return studentId;
	}

	public void setStudentId(int studentId) {
		this.studentId = studentId;
	}
	/**优惠相关**/

	public int getSigins() {
		return sigins;
	}

	public void setSigins(int sigins) {
		this.sigins = sigins;
	}

	public int getOrders() {
		return orders;
	}

	public void setOrders(int orders) {
		this.orders = orders;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public int getRank() {
		return rank;
	}

	public void setRank(int rank) {
		this.rank = rank;
	}

	/**
	 * 价格类型
	 * **/
	public static class PriceType{
		
		private String id; //编号ID
		//private Integer type;// 价格类型
		private Integer starton;// 起始人数
		private Integer endon;// 结束人数
		private Double price;// 价格
		
		/*public Integer getType() {
			return type;
		}
		public void setType(Integer type) {
			this.type = type;
		}*/
		public Integer getStarton() {
			return starton;
		}
		public void setStarton(Integer starton) {
			this.starton = starton;
		}
		public Integer getEndon() {
			return endon;
		}
		public void setEndon(Integer endon) {
			this.endon = endon;
		}
		public Double getPrice() {
			return price;
		}
		public void setPrice(Double price) {
			this.price = price;
		}
		public String getId() {
			return id;
		}
		public void setId(String id) {
			this.id = id;
		}
	}
}